package battlezone;

import java.io.*;
import java.net.*;
import javax.media.j3d.*;
import javax.vecmath.*;

public class Configuration {

    private static Configuration _instance;
    private static final ParameterObject _pObject = ParameterObject.getInstance();
    private static final GeometryObject _gObject = GeometryObject.getInstance();
    //private parameterObject pObject = new parameterObject();
    //private geometryObject gObject = new geometryObject();

    private Configuration() {
    }

    public static Configuration getInstance() {
        if (_instance == null) {
            _instance = new Configuration();
        }
        return _instance;
    }

    public InetAddress[] getIpAddresses() {
        return _pObject.getIpAddresses();
        //return pObject.ipAddresses;
    }              
    
    /**
     * Projectile velocity in meters per second
     */
    public float getProjectileVelocity() {
        // return 60;
        return _pObject.getProjectileVelocity();
    }    

    /**
     * Tank pivot rate in degrees per second
     */
    public float getTankPivotRate() {
        // return 60;
        return _pObject.getProjectileVelocity();
    }

    /**
     * Tank speed in meters per second
     */
    public float getTankSpeed() {
        // return 60;
        return _pObject.getTankSpeed();
    }

    public short getInitialNumberOfTanks() {
        // return 3;
        return _pObject.getInitialNumberOfTanks();
    }

    public short getSimultaneousProjectileCount() {
        // return 3;
        return _pObject.getSimultaneousProjectileCount();
    }

    /**
     * Engageability range in meters
     */
    public float getEngageabilityRange() {
        // return 150;
        return _pObject.getEngageabilityRange();
    }

    public short getInitialAmmunitionCount() {
        // return 12;
        return _pObject.getInitialAmmunitionCount();
    }

    /**
     * Detectability range in meters
     */
    public float getDetectabilityRange() {
        return _pObject.getDetectabilityRange();
    }

    /**
     * Rate of fire in rounds per minute
     */
    public float getRateOfFire() {
        return _pObject.getRateOfFire();
    }

    public File getMoveSoundFile() {
        return _pObject.getMoveSoundFile();
    }

    public File getFireSoundFile() {
        // return null;
        return _pObject.getFireSoundFile();
    }

    public File getKillSoundFile() {
        // return null;
        return _pObject.getKillSoundFile();
    }
    
    public Geometry getLiveTankGeometry() {
        Point3f[] points = new Point3f[0];
        points = _gObject.getModel("tank-live").toArray(points);
        LineArray geometry = new LineArray(points.length,  LineArray.COORDINATES | LineArray.COLOR_3);
        geometry.setCoordinates(0, points);
        for (int i = 0; i < points.length; i++) {
            geometry.setColor(i, this.getForegroundColor());
        }
        return geometry;
    }
    
    public Geometry getDeadTankGeometry() {
        Point3f[] points = new Point3f[0];
        points = _gObject.getModel("tank-dead").toArray(points);
        LineArray geometry = new LineArray(points.length,  LineArray.COORDINATES | LineArray.COLOR_3);
        geometry.setCoordinates(0, points);
        for (int i = 0; i < points.length; i++) {
            geometry.setColor(i, this.getForegroundColor());
        }
        return geometry;
    }
    
    public Geometry getProjectileGeometry() {
        Point3f[] points = new Point3f[0];
        points = _gObject.getModel("projectile").toArray(points);
        LineArray geometry = new LineArray(points.length,  LineArray.COORDINATES | LineArray.COLOR_3);
        geometry.setCoordinates(0, points);
        for (int i = 0; i < points.length; i++) {
            geometry.setColor(i, this.getForegroundColor());
        }
        return geometry;
    }
    
    
    /* Compile-time configuration parameters */
    /* These paramters are for configuring at compile time for our convenience, and are not required to be externally configurable. */
    
    public boolean getUseFullScreen() {
        return true;
    }

    /**
     * Returns the field width in meters.
     */
    public float getFieldWidth() {
        return 1000;
    }

    /**
     * Field height in meters
     */
    public float getFieldHeight() {
        return 1000;
    }

    /**
     * Reaction time in milliseconds
     */
    public long getReactionTime() {
        return 10;
    }
 
    private final Color3f _foregroundColor = new Color3f(0.1f, 0.8f, 0.1f);
    /**
     * "Battlezone green" color used for the view and the geometries
     */
    public Color3f getForegroundColor() {
        return _foregroundColor;
    }
    
    /**
     * Port number used for networking
     * @return
     */
    public short getPortNumber() {
        return 3000;
    }
    
    private String _playerName;
    public String getPlayerName() {
        return _playerName;
    }
    public void setPlayerName(String name) {
        _playerName = name;
    }
}